package com.hns.its.service.order;

import com.hns.its.dao.IItsBaseShippingScheduleDao;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * @ClassName ItsBaseShippingScheduleService
 * @Description xxl-job船期定时任务调度
 * @author 林亦杉
 * @email 417029059@qq.com
 * @Date 2018年9月13日
 * @version 1.0.0
 */
@Service
@Transactional(readOnly = true)
public class ItsBaseShippingScheduleService {

	@Autowired
	@PersistenceContext
	private EntityManager em;

	@Autowired
	private IItsBaseShippingScheduleDao iItsBaseShippingScheduleDao;

	/**
	 * 保存爬取船期
	 * @param sql
	 * void
	 */
	@Transactional(readOnly = false)
	public void saveCrawlerShippingSchedule(String sql){
		Query query = em.createNativeQuery("DELETE FROM its_base_shipping_schedule WHERE logistic_id IS NULL");
		int i = query.executeUpdate();
		XxlJobLogger.log("删除了(" + i + ")条物流商Id为空的船期记录！" );
		query = em.createNativeQuery(sql);
		i = query.executeUpdate();
		XxlJobLogger.log("插入了(" + i +")条船期记录！"  );
	}
}
